<?php

namespace App\Http\Controllers\Api\V1_0_0;

use App\Http\Controllers\Controller;
use App\Jobs\SendMail;
use App\Mail\Test;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use Mailgun\Mailgun;

class MailController extends Controller
{
    public function index(Request $request)
    {
        //测试邮件发送与短信发送
        //$data = [
        //    'title' => '测试邮件发送',
        //    'content' => '系统产生了一个错误，请尽快查看',
        //];
        ////暂时写死一个接收邮件，多个的话 explode 再遍历即可
        //$recipient = env('MAIL_RECIPIENT');
        //MAIL_MAILER=mailgun 发送邮件的两种方式
        // 1.通过 Mailgun 库
        //$mgClient = Mailgun::create('73b30362b1301822c9e0414fcdfff130-46ac6b00-e0d2651e', 'https://api.mailgun.net');
        //$domain = "sandboxde62417c40214f32a60bfa05f43e6b01.mailgun.org";
        //$params = array(
        //    'from'    => '674843367@qq.com',
        //    'to'      => '33723288@qq.com',
        //    'subject' => 'Tst',
        //    'text'    => 'Testing some Mailgun awesomness!'
        //);
        //$mgClient->messages()->send($domain, $params);
        // 2.通过 Laravel 自集成的 SwiftMailer 函数库
        //$recipient = explode(',', env('MAIL_RECIPIENT'));
        //foreach ($recipient as $item) {
        //    Mail::to($item)->cc('xxxx@qq.com')->bcc('xxxxx@qq.com')->send(new Test($data));
        //}

        //MAIL_MAILER=smtp 的发送方式
        //Mail::send('emails.default', $data, function ($message) use ($recipient) {
        //    //收件人的邮箱地址
        //    $message->to($recipient);
        //    //cc
        //    //$message->cc('xxxx@qq.com');
        //    //邮件主题
        //    $message->subject('测试');
        //    //邮件附件
        //    //$message->attach(resource_path('attach/test.md'));
        //});

        //邮件发送写入任务队列 指定 emails 队列
        //Mail::to($recipient)->queue((new Test($data))->onQueue('emails'));
        SendMail::dispatch()->onQueue('emails');
        return response()->json(['发送成功']);
    }
}
